<?php 
/**
 * 数据库备份
 */
class BackUpController extends CommonController{
	/**
	 * 备份列表
	 */
	public function index(){
		
		$data = Dir::tree('backup');
		$this->assign('data',$data);
	    $this->display();
	}
	
	public function recovery(){
		if(!session('dir')){
			session('dir',Q('post.dir'));
		}
		$dir = array('dir'=>session('dir'));
		$result = Backup::recovery($dir);
		//还原发生错误
		if ($result === false) {
			$this->error(Backup::$error);
		}else{
			 if ($result['status'] == 'success') {
			 	session('dir',NULL);
			 	//还原完毕 
			  	$this->success($result['message'], U('index'));
			  } else {
			  	//运行中... 
			  	$this->success($result['message'],$result['url'], 0.2);
			  }
		}
	}
	
	
	/**
	 * 数据库备份
	 */
	public function backup(){
		 $result = Backup::backup(
			 array(
			 	//分卷大小
			 	'size'      => 200,
			 	//备份目录 
			 	'dir'     => 'backup/' . date("Ymdhis") . '/',
			 	//备份时间间隔
			 	'step_time' => 1,
			)
		);
		if($result === false) {
			 //备份发生错误
			$this->error(Backup::$error, U('index'));
		}else{
			if($result['status'] == 'success'){
				//备份完成
				 $this->success($result['message'],U('index')); 
			}else{
				//备份过程中
				$this->success($result['message'], $result['url'], 0.2); 
			}
		}
			
	    $this->display();
	}
}










